﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Lottery.Herper;
using Lottery.MediaData.Core;
using Lottery.Control;
using Lottery.MediaData.UI.Control;

namespace Lottery.MediaData.UI {
    public partial class MainForm : Form {
        /// <summary>
        /// 包含了各个表格过滤表数据
        /// </summary>
        private Dictionary<string, FTCellData> m_fts = new Dictionary<string, FTCellData>();

        private string m_qiShu;
        /// <summary>
        /// 当前期数
        /// </summary>
        public string QiShu {
            get { return m_qiShu; }
            set {
                m_qiShu = value;
                this.Text = string.Format("足彩{1}场-缩水四表格 {0}期", m_qiShu, MaxCount);
                labelIndexInfo.Text = string.Format("足彩{1}场 期数：{0}", m_qiShu, MaxCount);
                tabControl.TabPages[tabControl.SelectedIndex].Focus();
                SetIndexData();

                SetControlEnabled();
            }
        }

        /// <summary>
        /// 足彩最大场次。目前只能是3-14
        /// </summary>
        public int MaxCount { get; set; }

        private string m_ccString = string.Empty;

        private List<int> m_cc;

        private void SetCC() {
            buttonLoadDataFromExcel.Visible = MaxCount == 14;
            buttonLoadData.Visible = MaxCount != 14;
            buttonLoadDataT2.Visible = MaxCount != 14;
            buttonLoadDataT3.Visible = MaxCount != 14;
            buttonLoadDataT4.Visible = MaxCount != 14;
            cbNine.Visible = MaxCount != 14;
            m_cc = new List<int>();
            if (MaxCount != 14) {
                var cc = DataHelper.LoadCC(QiShu, MaxCount);
                cbNine.Items.Clear();
                foreach (var c in cc) {
                    cbNine.Items.Add(c);
                }
                if (cbNine.Items.Count > 0) cbNine.SelectedIndex = 0;
            } else if (MaxCount == 14) {
                var sb = new StringBuilder();
                for (int i = 1; i < 15; i++) {
                    if (i != 1) sb.Append("-");
                    sb.Append(i);
                }
                cbNine.Items.Clear();
                cbNine.Items.Add(sb.ToString());
            }

            mediaDataInput.SetCC(m_cc);
            scInput.SetCC(m_cc);
            dzxInput.SetCC(m_cc);
            wzInput.SetCC(m_cc);
        }

        private void SetControlEnabled() {
            SetT1ControlEnabled(comboBoxT1SubIndex.SelectedIndex != -1);

            SetT2ControlEnabled(comboBoxT2SubIndex.SelectedIndex != -1);

            SetT3ControlEnabled(comboBoxT3SubIndex.SelectedIndex != -1);

            SetT4ControlEnabled(comboBoxT4SubIndex.SelectedIndex != -1);
        }

        private void SetT4ControlEnabled(bool enabled) {
            wzInput.Enabled = enabled;
            wzGrid.Enabled = enabled;
            buttonSaveT4Data.Enabled = enabled;
            buttonCombineT4Data.Enabled = enabled;
            buttonGenT4FilterTable.Enabled = enabled;
        }

        private void SetT3ControlEnabled(bool enabled) {
            dzxInput.Enabled = enabled;
            dzxGrid.Enabled = enabled;
            buttonT3CopyData.Enabled = enabled;
            buttonCombineT3Data.Enabled = enabled;
            buttonGenT3FilterTable.Enabled = enabled;
        }

        private void SetT2ControlEnabled(bool enabled) {
            scInput.Enabled = enabled;
            dataLimitInputSC.Enabled = enabled;
            buttonT2CopyData.Enabled = enabled;
            buttonCombineT2Data.Enabled = enabled;
            buttonGenT2FilterTable.Enabled = enabled;
            buttonLine2.Enabled = enabled;
            combineLineT2.Enabled = enabled;
        }

        private void SetT1ControlEnabled(bool enabled) {
            mediaDataInput.Enabled = enabled;
            dataLimitInput.Enabled = enabled;
            buttonSaveMediaData.Enabled = enabled;
            buttonDataCombine.Enabled = enabled;
            buttonGenFilterTable.Enabled = enabled;
            buttonLine1.Enabled = enabled;
            combineLineT1.Enabled = enabled;
        }

        public MainForm(int maxCount)
            : this() {
            MaxCount = maxCount;
        }

        private MainForm() {
            InitializeComponent();

            this.Text = "足彩缩水";

            this.WindowState = FormWindowState.Maximized;

            dzxGrid.InitGrid();
            wzGrid.InitGrid();
        }

        /// <summary>
        /// 足彩期数
        /// </summary>
        private void SetIndexData() {
            // table 1
            mediaDataInput.ClearData();
            dataLimitInput.HideAll();
            comboBoxT1SubIndex.Items.Clear();

            // table 2
            scInput.ClearData();
            dataLimitInputSC.HideAll();
            comboBoxT2SubIndex.Items.Clear();

            // table 3
            dzxInput.ClearData();
            dzxGrid.ClearData();
            comboBoxT3SubIndex.Items.Clear();

            // table 4
            //wzInput.
            wzInput.ClearData();
            wzGrid.ClearData();
            comboBoxT4SubIndex.Items.Clear();

            if (MaxCount == 14) {
                cbNine.Visible = false;
                buttonNewCC.Visible = false;
                buttonDeleteCC.Visible = false;
                buttonLoadCCFromExcel.Visible = false;

                // 十四场
                var list = new List<int>();
                for (int i = 0; i < 14; i++) {
                    list.Add(i);
                }
                m_cc = list;
                m_ccString = string.Empty;

                SetComboBoxT1IndexData(QiShu, m_ccString);
                SetComboBoxT2IndexData(QiShu, m_ccString);
                SetComboBoxT3IndexData(QiShu, m_ccString);
                SetComboBoxT4IndexData(QiShu, m_ccString);
            } else {
                // 3-13场
                cbNine.Visible = true;
                buttonNewCC.Visible = true;
                buttonDeleteCC.Visible = true;
                buttonLoadCCFromExcel.Visible = true;
                buttonGenAllFilterTable.Text = "生成当前场次组合全部过滤表";
                SetCC();
            }
        }

        /// <summary>
        /// 设置每场中的各个媒体数据。
        /// </summary>
        private void SetComboBoxT1IndexData(string qiShu, string cc) {
            comboBoxT1SubIndex.Items.Clear();
            comboBoxT1SubIndex.Items.AddRange(DataHelper.GetT1SubIndexes(qiShu, cc, MaxCount));

            if (comboBoxT1SubIndex.Items.Count != 0)
                comboBoxT1SubIndex.SelectedIndex = 0;
        }

        private void SetComboBoxT2IndexData(string qiShu, string cc) {
            comboBoxT2SubIndex.Items.Clear();
            comboBoxT2SubIndex.Items.AddRange(DataHelper.GetT2SubIndexes(qiShu, cc, MaxCount));
            comboBoxT2SubIndex.SelectedIndex = comboBoxT2SubIndex.Items.IndexOf(qiShu);
            if (comboBoxT2SubIndex.SelectedIndex == -1 && comboBoxT2SubIndex.Items.Count != 0) {
                comboBoxT2SubIndex.SelectedIndex = 0;
            }
        }

        private void comboBoxT1SubIndex_SelectedIndexChanged(object sender, EventArgs e) {
            SetT1ControlEnabled(comboBoxT1SubIndex.SelectedIndex != -1);

            mediaDataInput.ClearData();
            dataLimitInput.HideAll();
            mediaDataInput.SetCC(m_cc);

            combineLineT1.ClearData();

            if (string.IsNullOrEmpty(comboBoxT1SubIndex.Text)) {
                return;
            }

            List<DS> data;
            List<FD> filter;
            CL c;
            DataHelper.LoadT1Data(QiShu, m_ccString, MaxCount, comboBoxT1SubIndex.Text,
                out data, out filter, out c);
            for (int i = 0; i < data.Count; i++) {
                var item = mediaDataInput[i];
                var d = data[i];
                item.Order = i + 1;
                item.Three = d.Three;
                item.One = d.One;
                item.Zero = d.Zero;
                item.PreNumber = d.PreNumber;
            }
            int index = 0;
            foreach (var item in filter) {
                DataLimit dl = dataLimitInput[index++];
                dl.SetData(item.MediaCount, item.Count, item.Low, item.Up, item.IsAttended);
                dl.Visible = true;
            }
            for (int i = index; i < dataLimitInput.Count; i++) {
                dataLimitInput[i].Visible = false;
            }

            combineLineT1.From1 = c.From1;
            combineLineT1.To1 = c.To1;
            combineLineT1.From2 = c.From2;
            combineLineT1.To2 = c.To2;
        }

        private void button1_Click(object sender, EventArgs e) {
            if (MaxCount != 14 && m_ccString == string.Empty) {
                this.ShowInfo("请选择场次");

                return;
            }

            if (this.ShowYesNoInfo("请确认是否新增序号") != DialogResult.Yes) {
                return;
            }

            var subIndex = DataHelper.AutoIncSubIndex("T1", QiShu, m_ccString, MaxCount);
            SetComboBoxT1IndexData(QiShu, m_ccString);
            comboBoxT1SubIndex.SelectedIndex = comboBoxT1SubIndex.Items.IndexOf(subIndex);

            mediaDataInput.Focus();
        }

        private void buttonSaveMediaData_Click(object sender, EventArgs e) {
            // 保存数据

            if (comboBoxT1SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < 14; i++) {
                var item = mediaDataInput[i];
                if (!item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.Focus();
                    return;
                }
            }

            // 保存媒体数据
            SaveT1Data();

            this.ShowInfo("成功保存数据");
            mediaDataInput.Focus();
        }

        /// <summary>
        /// 保存 表一：媒体数据
        /// </summary>
        private void SaveT1Data() {
            var d = new List<DS>();
            var f = new List<FD>();
            for (int i = 0; i < mediaDataInput.Count; i++) {
                var item = mediaDataInput[i];
                if (item.Enabled)
                    d.Add(new DS(item.Three, item.One, item.Zero, item.PreNumber));
                else
                    d.Add(new DS(int.MinValue, int.MinValue, int.MinValue, ""));
            }

            for (int i = 0; i < dataLimitInput.Count; i++) {
                var item = dataLimitInput[i];
                if (!item.Visible) {
                    break;
                }

                f.Add(new FD(item.MediaCount, item.Count, item.Low, item.Up, item.Attended));
            }

            var c = new CL();
            c.From1 = combineLineT1.From1;
            c.To1 = combineLineT1.To1;
            c.From2 = combineLineT1.From2;
            c.To2 = combineLineT1.To2;

            DataHelper.SaveT1Data(QiShu, m_ccString, MaxCount, comboBoxT1SubIndex.Text, d, f, c);
        }

        private void buttonDataCombine_Click(object sender, EventArgs e) {
            if (comboBoxT1SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < mediaDataInput.Count; i++) {
                var item = mediaDataInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            if (this.ShowYesNoInfo("请确认是否进行数据合并?") != DialogResult.Yes) {
                return;
            }

            // 数据合并
            var allDatas = new List<DS>();
            for (int i = 0; i < mediaDataInput.Count; i++) {
                var item = mediaDataInput[i];
                if (item.Enabled)
                    allDatas.Add(new DS(item.Three, item.One, item.Zero, item.PreNumber));
            }

            var result = DSHelper.ProcessAllData(allDatas);
            SetCombineDataForTalbe1(result);

            combineLineT1.ClearData();


            //设置局部默认值 2010-11-30
            #region 局部默认值说明
            //四表格软件表1局部默认：
            //一、表1界面内：（若出现以下数据相矛盾时，交叉重叠时，软件可只显示一部分默认数据）
            //1、7项合的媒体数据：6、7两数不参与总数的合并，其中的“√”默认为“空白”；
            //区域一：（小数）6～7（大数)→（或无6时为5～7；→最大两个数间）
            //区域二：（小数）0～2（大数)→（或无2时为0～3；或无0时为1～3；→最小三个数间，并非一定是三个数）

            //2、14项合的媒体数据：13、14两数不参与总数的合并，其中的“√”默认为“空白”；
            //区域一：（小数）13～14（大数)→（或无13时为12～14；→最大两个数间）
            //区域二：（小数）0～7（大数)→（或无7时为0～8；或无0时为1～8；→最小八个数间，并非一定是八个数）

            //3、19项合的媒体数据：18、19两数不参与总数的合并，其中的“√”默认为“空白”；
            //区域一：（小数）18～19（大数)→（或无18时为17～19；→最大两个数间）
            //区域二：（小数）0～9（大数)→（或无9时为0～10；或无0时为1～10；→最小十个数间，并非一定是十个数）

            //4、26项合的媒体数据：24、25、26三个数不参与总数的合并，其中的“√”默认为“空白”；
            //区域一：（小数）24～26（大数)→（或无24时为23～26；→最大三个数间）
            //区域二：（小数）0～11（大数)→（或无11时为0～12；或无0时为1～12；→最小12个数间，并非一定是12
            //个数）

            //5、45项合的媒体数据：43、44、45三个数不参与总数的合并，其中的“√”默认为“空白”；
            //区域一：（小数）43～45（大数)→（或无43时为42～45；→最大三个数间）
            //区域二：（小数）0～11（大数)→（或无11时为0～12；或无0时为1～12；→最小12个数间，并非一定是12
            //个数
            #endregion
            var vCount = dataLimitInput.VisibleCount;
            var maxValue = dataLimitInput[0].MediaCount;
            if (maxValue == 7 || maxValue == 6) {
                dataLimitInput[0].Attended = false;
                dataLimitInput[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInput[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 1) combineLineT1.From1 = combines[1];
                combineLineT1.To1 = combines[0];

                combineLineT1.From2 = combines[combines.Count - 1];

                var t2 = (from item in sl
                          where item == 2 || item == 3
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT1.To2 = t2[0];
                    if (combineLineT1.To2 >= combineLineT1.From1) combineLineT1.To2 = -1;
                }
            } else if (maxValue == 14 || maxValue == 13) {
                dataLimitInput[0].Attended = false;
                dataLimitInput[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInput[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 1) combineLineT1.From1 = combines[1];
                combineLineT1.To1 = combines[0];

                combineLineT1.From2 = combines[combines.Count - 1];

                var t2 = (from item in sl
                          where item == 7 || item == 8
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT1.To2 = t2[0];
                    if (combineLineT1.To2 >= combineLineT1.From1) combineLineT1.To2 = -1;
                }
            } else if (maxValue == 19 || maxValue == 18) {
                dataLimitInput[0].Attended = false;
                dataLimitInput[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInput[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 1) combineLineT1.From1 = combines[1];
                combineLineT1.To1 = combines[0];

                combineLineT1.From2 = combines[combines.Count - 1];

                var t2 = (from item in sl
                          where item == 9 || item == 10
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT1.To2 = t2[0];
                    if (combineLineT1.To2 >= combineLineT1.From1) combineLineT1.To2 = -1;
                }
            } else if (maxValue == 26 || maxValue == 25 || maxValue == 24) {
                dataLimitInput[0].Attended = false;
                dataLimitInput[1].Attended = false;
                dataLimitInput[2].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInput[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 2) combineLineT1.From1 = combines[2];
                combineLineT1.To1 = combines[0];

                combineLineT1.From2 = combines[combines.Count - 1];

                var t2 = (from item in sl
                          where item == 11 || item == 12
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT1.To2 = t2[0];
                    if (combineLineT1.To2 >= combineLineT1.From1) combineLineT1.To2 = -1;
                }
            } else if (maxValue == 45 || maxValue == 44 || maxValue == 43) {
                dataLimitInput[0].Attended = false;
                dataLimitInput[1].Attended = false;
                dataLimitInput[2].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInput[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 2) combineLineT1.From1 = combines[2];
                combineLineT1.To1 = combines[0];

                combineLineT1.From2 = combines[combines.Count - 1];

                var t2 = (from item in sl
                          where item == 11 || item == 12
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT1.To2 = t2[0];
                    if (combineLineT1.To2 >= combineLineT1.From1) combineLineT1.To2 = -1;
                }
            }
            // end 2010-11-30

            if (maxValue == 33 || maxValue == 32 || maxValue == 31) {
                dataLimitInput[0].Attended = false;
                dataLimitInput[1].Attended = false;
                dataLimitInput[2].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInput[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 2) combineLineT1.From1 = combines[2];
                combineLineT1.To1 = combines[0];

                combineLineT1.From2 = combines[combines.Count - 1];

                var t2 = (from item in sl
                          where item == 11 || item == 12
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT1.To2 = t2[0];
                    if (combineLineT1.To2 >= combineLineT1.From1) combineLineT1.To2 = -1;
                }
            }

            SaveT1Data();
        }

        private void SetCombineData(DataLimitInput input, Dictionary<int, int> data) {
            if (data == null) return;

            input.Visible = false;
            input.HideAll();

            var index = 0;
            foreach (var item in data) {
                var dl = input[index++];
                dl.Visible = true;
                dl.SetData(item.Key, item.Value);
                dl.Attended = true;
            }
            input.Visible = true;
        }

        private void SetCombineDataForTalbe1(Dictionary<int, int> data) {
            SetCombineData(dataLimitInput, data);
        }

        private void SetCombineDataForTalbe2(Dictionary<int, int> data) {
            SetCombineData(dataLimitInputSC, data);
        }

        private void buttonGenFilterTable_Click(object sender, EventArgs e) {
            // 表一 生成 过滤表

            if (comboBoxT1SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < mediaDataInput.Count; i++) {
                var item = mediaDataInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            bool hasCombinData = false;
            for (int i = 0; i < dataLimitInput.Count; i++) {
                if (dataLimitInput[i].Visible) {
                    hasCombinData = true;
                    break;
                }
            }
            if (!hasCombinData) {
                this.ShowInfo("没有进行数据合并");
                this.Focus();
                return;
            }

            for (int i = 0; i < dataLimitInput.Count; i++) {
                var item = dataLimitInput[i];
                if (!item.Visible)
                    continue;

                if (!item.IsOK) {
                    item.Focus();
                    this.ShowInfo(string.Format("[ 排列 {0} 合并 {1} ]的过滤数据录入不正确", item.MediaCount, item.Count));
                    return;
                }
            }

            if (combineLineT1.From1 == -1) {
                this.ShowInfo("没有设置合并行的数据");
                return;
            }

            SaveT1Data();

            var allDatas = new List<DS>();
            for (int i = 0; i < mediaDataInput.Count; i++) {
                var item = mediaDataInput[i];
                if (item.Enabled)
                    allDatas.Add(new DS(item.Three, item.One, item.Zero, item.PreNumber));
                else
                    allDatas.Add(new DS(int.MinValue, int.MinValue, int.MinValue, ""));
            }

            var com = new List<FD>();
            for (int i = 0; i < dataLimitInput.Count; i++) {
                var item = dataLimitInput[i];
                if (!item.Visible) {
                    break;
                }

                com.Add(new FD(item.MediaCount, item.Count, item.Low, item.Up, item.Attended));
            }

            var ft = new FTCellData();
            MDHelper.Gen(ft, allDatas, com, comboBoxT1SubIndex.Text);
            if (ft.RowCount == 0) {
                this.ShowInfo("当前过滤表中没有数据");
                return;
            }

            var c = new CL();
            c.From1 = combineLineT1.From1;
            c.To1 = combineLineT1.To1;
            c.From2 = combineLineT1.From2;
            c.To2 = combineLineT1.To2;

            MDHelper.CombineLine(ft, com, c);

            string key;
            if (m_ccString == string.Empty)
                key = string.Format("1-{0}", comboBoxT1SubIndex.Text);
            else
                key = string.Format("1-[{1}]-{0}", comboBoxT1SubIndex.Text, m_ccString);

            if (m_fts.ContainsKey(key))
                m_fts[key] = ft;
            else
                m_fts.Add(key, ft);

            ShowFilterForm(QiShu, key);
        }

        private void button2_Click(object sender, EventArgs e) {
            for (int i = 0; i < dzxInput.Count; i++) {
                dzxInput[i].SetDZXLabelInfo();
            }
        }

        private void MainForm_Load(object sender, EventArgs e) {
        }

        private void button3_Click(object sender, EventArgs e) {
            if (comboBoxT3SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < dzxInput.Count; i++) {
                var item = dzxInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            if (this.ShowYesNoInfo("请确认是否进行数据合并?") != DialogResult.Yes) {
                return;
            }

            var data = new List<DZX>();
            for (int i = 0; i < dzxInput.Count; i++) {
                var dzx = dzxInput[i];
                if (dzx.Enabled) {
                    dzx.SetDZXLabelInfo();
                    data.Add(new DZX { D = dzx.D, Z = dzx.Z, X = dzx.X, PreNumber = dzx.PreNumber, PreText = dzx.PreText });
                } else
                    data.Add(new DZX {
                        D = "", Z = "", X = "", PreNumber = "", Three = int.MinValue, One = int.MinValue,
                        Zero = int.MinValue, PreText = string.Empty
                    });
            }

            dzxGrid.SetCellData(DZXHelper.Gen(data));

            SaveT3Data(comboBoxT3SubIndex.Text);
        }

        private void button2_Click_1(object sender, EventArgs e) {
            // 表四 文字 -- 数据合并
            for (int i = 0; i < wzInput.Count; i++) {
                var item = wzInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.Focus();
                    return;
                }

                if (item.Enabled && !item.InputIsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据录入错误：3、1、0的文字相同。", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            if (this.ShowYesNoInfo("请确认是否进行数据合并?") != DialogResult.Yes) {
                return;
            }

            var data = new List<WZ>();
            for (int i = 0; i < wzInput.Count; i++) {
                var wz = wzInput[i];
                if (wz.Enabled)
                    data.Add(new WZ { Three = wz.Three, One = wz.One, Zero = wz.Zero, PreText = wz.PreText });
                else
                    data.Add(new WZ { Three = "", One = "", Zero = "", PreText = "" });

            }

            wzGrid.SetCellData(WZHelper.Gen(data));

            SaveT4Data(comboBoxT4SubIndex.Text);
        }

        private void button4_Click(object sender, EventArgs e) {
            // 媒体数据－每场大中小数差 数据合并 表二
            if (comboBoxT2SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < 14; i++) {
                var item = scInput[i];
                item.CalcDZX();
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            if (this.ShowYesNoInfo("请确认是否进行数据合并?") != DialogResult.Yes) {
                return;
            }

            var data = new List<SC>();
            for (int i = 0; i < scInput.Count; i++) {
                var s = scInput[i];
                if (s.Enabled) {
                    s.CalcDZX();
                    data.Add(new SC { D = s.D, Z = s.Z, X = s.X, PreNumber = s.PreNumber });
                } else
                    data.Add(new SC { D = "", Z = "", X = "", PreNumber = "" });
            }

            var result = SCHelper.ProcessAllData(data);
            SetCombineDataForTalbe2(result);

            combineLineT2.ClearData();

            // 局部默认数据 2010-11-30
            #region
            //四表格软件表2局部默认：
            //一、表2界面内：（若出现以下数据相矛盾时，交叉重叠时，软件可只显示一部分默认数据）
            //1、7项合的媒体数据：
            //区域一：（小数）6～7（大数)→（或无6时为5～7；→最大两个数间）
            //区域二：（小数）1～2（大数)→（或无2时为1～3；或无1时为2～3；→最小两个数间）

            //2、14项合的媒体数据：
            //区域一：（小数）13～14（大数)→（或无13时为12～14；→最大两个数间）
            //区域二：（小数）1～7（大数)→（或无7时为1～8；或无1时为2～8；→最小七个数间，并非一定是七个数）

            //3、19项合的媒体数据：
            //区域一：（小数）17～19（大数)→（或无17时为16～19；→最大三个数间）
            //区域二：（小数）1～10（大数)→（或无10时为1～11；或无1时为2～11；→最小十个数间，并非一定是十
            //个数）

            //4、26项合的媒体数据：
            //区域一：（小数）24～26（大数)→（或无24时为23～26；→最大三个数间）
            //区域二：（小数）1～11（大数)→（或无11时为1～12；或无1时为2～12；→最小11个数间，并非一定是11
            //个数）

            //5、45项合的媒体数据：
            //区域一：（小数）43～45（大数)→（或无43时为42～45；→最大三个数间）
            //区域二：（小数）1～11（大数)→（或无11时为1～12；或无1时为2～12；→最小11个数间，并非一定是11
            //个数）
            //注;本次未提到的按原软件不变。
            #endregion
            var vCount = dataLimitInputSC.VisibleCount;
            var maxValue = dataLimitInputSC[0].MediaCount;
            if (maxValue == 7 || maxValue == 6) {
                //dataLimitInputSC[0].Attended = false;
                //dataLimitInputSC[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInputSC[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 1) combineLineT2.From1 = combines[1];
                combineLineT2.To1 = combines[0];

                combineLineT2.From2 = combines[cnt - 1];
                var t2 = (from item in sl
                          where item == 2 || item == 3
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT2.To2 = t2[0];
                    if (combineLineT2.To2 >= combineLineT2.From1) combineLineT2.To2 = -1;
                }
            } else if (maxValue == 14 || maxValue == 13) {
                //dataLimitInputSC[0].Attended = false;
                //dataLimitInputSC[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInputSC[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 1) combineLineT2.From1 = combines[1];
                combineLineT2.To1 = combines[0];

                combineLineT2.From2 = combines[cnt - 1];
                var t2 = (from item in sl
                          where item == 7 || item == 8
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT2.To2 = t2[0];
                    if (combineLineT2.To2 >= combineLineT2.From1) combineLineT2.To2 = -1;
                }
            } else if (maxValue == 19 || maxValue == 18 || maxValue == 17) {
                //dataLimitInputSC[0].Attended = false;
                //dataLimitInputSC[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInputSC[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 2) combineLineT2.From1 = combines[2];
                combineLineT2.To1 = combines[0];

                combineLineT2.From2 = combines[cnt - 1];
                var t2 = (from item in sl
                          where item == 10 || item == 11
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT2.To2 = t2[0];
                    if (combineLineT2.To2 >= combineLineT2.From1) combineLineT2.To2 = -1;
                }
            } else if (maxValue == 26 || maxValue == 25 || maxValue == 24
                || maxValue == 33 || maxValue == 32 || maxValue == 31
                || maxValue == 45 || maxValue == 44 || maxValue == 43) {
                //dataLimitInputSC[0].Attended = false;
                //dataLimitInputSC[1].Attended = false;

                var sl = new List<int>();
                for (int i = 0; i < vCount; i++) {
                    var dl = dataLimitInputSC[i];
                    sl.Add(dl.MediaCount);
                }

                var combines = (from item in sl
                                orderby item descending
                                select item).ToList();

                var cnt = combines.Count;
                if (cnt > 2) combineLineT2.From1 = combines[2];
                combineLineT2.To1 = combines[0];

                combineLineT2.From2 = combines[cnt - 1];
                var t2 = (from item in sl
                          where item == 11 || item == 12
                          orderby item
                          select item).ToList();
                if (t2.Count > 0) {
                    combineLineT2.To2 = t2[0];
                    if (combineLineT2.To2 >= combineLineT2.From1) combineLineT2.To2 = -1;
                }
            }
            // end 2010-11-30

            SaveT2Data(comboBoxT2SubIndex.Text);
        }

        private void button5_Click(object sender, EventArgs e) {
            // 过滤表
            ShowFilterForm(QiShu, string.Empty);
        }

        /// <summary>
        /// 显示过滤表窗体
        /// </summary>
        private void ShowFilterForm(string qiShu, string key) {
            var form = new FilterTableForm(m_fts, key);
            form.QiShu = qiShu;
            form.CC = m_ccString;
            form.MaxCount = this.MaxCount;
            form.CCIndex = cbNine.SelectedIndex + 1;
            form.ShowDialog();
        }

        private void button6_Click(object sender, EventArgs e) {
            //大中下 生成过滤表 表三
            if (comboBoxT3SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < dzxInput.Count; i++) {
                var item = dzxInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            if (!dzxGrid.HasData) {
                this.ShowInfo("没有进行数据合并，不能生成过滤表");
                return;
            }

            for (int row = 0; row < dzxGrid.RowCount; row++) {
                if (!dzxGrid.CheckData(row)) {
                    dzxGrid.CurrentCell = dzxGrid[17, row];
                    this.ShowInfo(string.Format("第{0}行数据录入错误", row + 1));
                    dzxGrid.Focus();
                    return;
                }
            }

            var ft = new FTCellData();
            var subIndex = comboBoxT3SubIndex.Text;
            dzxGrid.GenFtCellData(ft, subIndex);
            if (ft.RowCount == 0) {
                this.ShowInfo("当前过滤表中没有数据");
                return;
            }
            string key;
            if (m_ccString == string.Empty)
                key = string.Format("3-{0}", subIndex);
            else
                key = string.Format("3-[{1}]-{0}", subIndex, m_ccString);

            if (m_fts.ContainsKey(key))
                m_fts[key] = ft;
            else
                m_fts.Add(key, ft);

            SaveT3Data(subIndex);

            ShowFilterForm(QiShu, key);
        }

        private void button7_Click(object sender, EventArgs e) {
            // 表四 文字 生成过滤表
            for (int i = 0; i < wzInput.Count; i++) {
                var item = wzInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.Focus();
                    return;
                }

                if (item.Enabled && !item.InputIsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据录入错误：3、1、0的文字相同。", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            if (!dzxGrid.HasData) {
                this.ShowInfo("没有进行数据合并，不能生成过滤表");
                return;
            }

            for (int row = 0; row < wzGrid.RowCount; row++) {
                if (!wzGrid.CheckData(row)) {
                    wzGrid.CurrentCell = wzGrid[17, row];
                    this.ShowInfo(string.Format("第{0}行数据录入错误", row + 1));
                    wzGrid.Focus();
                    return;
                }
            }

            var ft = new FTCellData();
            var subIndex = comboBoxT4SubIndex.Text;
            wzGrid.GenFtCellData(ft, subIndex);
            if (ft.RowCount == 0) {
                this.ShowInfo("当前过滤表中没有数据");
                return;
            }
            string key;
            if (m_ccString == string.Empty)
                key = string.Format("4-{0}", subIndex);
            else
                key = string.Format("4-[{1}]-{0}", subIndex, m_ccString);
            m_fts[key] = ft;

            SaveT4Data(subIndex);

            ShowFilterForm(QiShu, key);
        }

        private void button8_Click(object sender, EventArgs e) {
            //表2 生成过滤表
            if (comboBoxT2SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            for (int i = 0; i < scInput.Count; i++) {
                var item = scInput[i];
                if (item.Enabled && !item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.FocusOnEmptyEdit();
                    return;
                }
            }

            bool hasCombinData = false;
            for (int i = 0; i < scInput.Count; i++) {
                if (scInput[i].Visible) {
                    hasCombinData = true;
                    break;
                }
            }
            if (!hasCombinData) {
                this.ShowInfo("没有进行数据合并");
                this.Focus();
                return;
            }

            for (int i = 0; i < dataLimitInputSC.Count; i++) {
                var item = dataLimitInputSC[i];
                if (!item.Visible)
                    continue;

                if (!item.IsOK) {
                    item.Focus();
                    this.ShowInfo(string.Format("[ 排列 {0} 合并 {1} ]的过滤数据录入不正确", item.MediaCount, item.Count));
                    return;
                }
            }

            if (combineLineT2.From1 == -1) {
                this.ShowInfo("没有设置合并行的数据");
                return;
            }

            var allDatas = new List<SC>();
            for (int i = 0; i < 14; i++) {
                var item = scInput[i];
                if (item.Enabled)
                    allDatas.Add(new SC() {
                        D = item.D, Z = item.Z, X = item.X, PreNumber = item.PreNumber,
                        Three = item.Three, One = item.One, Zero = item.Zero
                    });
                else
                    allDatas.Add(new SC() {
                        D = "", Z = "", X = "", PreNumber = "",
                        Three = int.MinValue, One = int.MinValue, Zero = int.MinValue
                    });
            }

            var com = new List<FD>();
            for (int i = 0; i < dataLimitInputSC.Count; i++) {
                var item = dataLimitInputSC[i];
                if (!item.Visible) {
                    break;
                }

                com.Add(new FD(item.MediaCount, item.Count, item.Low, item.Up, item.Attended));
            }

            var ft = new FTCellData();
            var subIdex = comboBoxT2SubIndex.Text;
            SCHelper.Gen(ft, allDatas, com, subIdex);
            if (ft.RowCount == 0) {
                this.ShowInfo("当前过滤表中没有数据");
                return;
            }

            var c = new CL();
            c.From1 = combineLineT2.From1;
            c.To1 = combineLineT2.To1;
            c.From2 = combineLineT2.From2;
            c.To2 = combineLineT2.To2;

            SCHelper.CombineLine(ft, com, c);

            string key;
            if (m_ccString == string.Empty)
                key = string.Format("2-{0}", subIdex);
            else
                key = string.Format("2-[{1}]-{0}", subIdex, m_ccString);

            if (m_fts.ContainsKey(key))
                m_fts[key] = ft;
            else
                m_fts.Add(key, ft);

            SaveT2Data(subIdex);

            ShowFilterForm(QiShu, key);
        }

        private void button10_Click(object sender, EventArgs e) {
            // 表2 新增序号
            if (MaxCount != 14 && m_ccString == string.Empty) {
                this.ShowInfo("请选择场次");

                return;
            }

            if (this.ShowYesNoInfo("请确认是否新增序号") != DialogResult.Yes) {
                return;
            }

            var subIndex = DataHelper.AutoIncSubIndex("T2", QiShu, m_ccString, MaxCount);
            SetComboBoxT2IndexData(QiShu, m_ccString);
            comboBoxT2SubIndex.SelectedIndex = comboBoxT2SubIndex.Items.IndexOf(subIndex);
            scInput.Focus();
        }

        private void button11_Click(object sender, EventArgs e) {
            // 表2 复制表一数据
            if (comboBoxT2SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            var order = comboBoxT2SubIndex.Text;
            if (comboBoxT1SubIndex.Items.IndexOf(order) == -1) {
                this.ShowInfo(string.Format("表1中还没有序号 {0} ", order));
                return;
            }

            if (this.ShowYesNoInfo("请确认是否进行数据复制?") != DialogResult.Yes) {
                scInput.Focus();
                return;
            }

            dataLimitInputSC.HideAll();
            List<DS> d;
            List<FD> f;
            CL c;
            DataHelper.LoadT1Data(QiShu, m_ccString, MaxCount, order, out d, out f, out c);
            if (d == null || d.Count == 0) {
                this.ShowInfo("表1中没有数据，无法复制");
                return;
            }
            for (int i = 0; i < scInput.Count; i++) {
                var item = scInput[i];
                var data = d[i];
                item.Three = data.Three;
                item.One = data.One;
                item.Zero = data.Zero;
                item.CalcDZX();
            }
            this.ShowInfo("成功复制数据");
            scInput.Focus();
        }

        /// <summary>
        /// 保存表二的数据
        /// </summary>
        /// <param name="order">序号</param>
        private void SaveT2Data(string order) {
            var d = new List<SC>();
            var f = new List<FD>();
            for (int i = 0; i < scInput.Count; i++) {
                var item = scInput[i];
                if (item.Enabled)
                    d.Add(new SC() {
                        Three = item.Three, One = item.One, Zero = item.Zero, PreNumber = item.PreNumber,
                        D = item.D, Z = item.Z, X = item.X
                    });
                else
                    d.Add(new SC() {
                        Three = int.MinValue, One = int.MinValue, Zero = int.MinValue, PreNumber = "",
                        D = "", Z = "", X = ""
                    });
            }

            for (int i = 0; i < dataLimitInputSC.Count; i++) {
                var item = dataLimitInputSC[i];
                if (!item.Visible) {
                    break;
                }

                f.Add(new FD(item.MediaCount, item.Count, item.Low, item.Up, item.Attended));
            }

            CL c = new CL();
            c.From1 = combineLineT2.From1;
            c.To1 = combineLineT2.To1;
            c.From2 = combineLineT2.From2;
            c.To2 = combineLineT2.To2;

            DataHelper.SaveT2Data(QiShu, m_ccString, MaxCount, order, d, f, c);
        }

        /// <summary>
        /// 保存表3的数据
        /// </summary>
        /// <param name="order">序号</param>
        private void SaveT3Data(string order) {
            var d = new List<DZX>();
            for (int i = 0; i < dzxInput.Count; i++) {
                var item = dzxInput[i];
                if (item.Enabled)
                    d.Add(new DZX() {
                        D = item.D, Z = item.Z, X = item.X,
                        Three = item.Three, One = item.One, Zero = item.Zero,
                        PreNumber = item.PreNumber, PreText = item.PreText
                    });
                else
                    d.Add(new DZX() {
                        D = "", Z = "", X = "",
                        Three = int.MinValue, One = int.MinValue, Zero = int.MinValue,
                        PreNumber = "", PreText = ""
                    });
            }

            var cellData = dzxGrid.GetCellData();
            DataHelper.SaveT3Data(QiShu, m_ccString, MaxCount, order, d, cellData);
        }

        private void comboBoxT2SubIndex_SelectedIndexChanged(object sender, EventArgs e) {
            SetT2ControlEnabled(comboBoxT2SubIndex.SelectedIndex != -1);

            scInput.ClearData();
            dataLimitInputSC.HideAll();
            scInput.SetCC(m_cc);

            combineLineT2.ClearData();

            if (string.IsNullOrEmpty(comboBoxT2SubIndex.Text)) {
                return;
            }

            List<SC> data;
            List<FD> filter;
            CL c;
            DataHelper.LoadT2Data(QiShu, m_ccString, MaxCount, comboBoxT2SubIndex.Text, out data,
                out filter, out c);
            for (int i = 0; i < data.Count; i++) {
                var item = scInput[i];
                var d = data[i];
                item.Order = i + 1;
                item.Three = d.Three;
                item.One = d.One;
                item.Zero = d.Zero;
                item.PreNumber = d.PreNumber;
                item.D = d.D;
                item.Z = d.Z;
                item.X = d.X;
                item.CalcDZX();
            }
            int index = 0;
            foreach (var item in filter) {
                DataLimit dl = dataLimitInputSC[index++];
                dl.SetData(item.MediaCount, item.Count, item.Low, item.Up, item.IsAttended);
                dl.Visible = true;
            }
            for (int i = index; i < dataLimitInputSC.Count; i++) {
                dataLimitInputSC[i].Visible = false;
            }

            combineLineT2.From1 = c.From1;
            combineLineT2.To1 = c.To1;
            combineLineT2.From2 = c.From2;
            combineLineT2.To2 = c.To2;
        }

        private void button12_Click(object sender, EventArgs e) {
            // 打开过滤表文件夹
            var path = DataHelper.GetExcelPath(MaxCount);
            if (!System.IO.Directory.Exists(path))
                System.IO.Directory.CreateDirectory(path);

            System.Diagnostics.Process.Start("explorer.exe", path);
        }

        private void buttonSelectIndex_Click(object sender, EventArgs e) {
            // 选择足彩期数
            var form = new SelectIndexForm();
            form.Text = string.Format("足彩{0}场", MaxCount);
            if (form.ShowDialog() == DialogResult.OK) {
                this.QiShu = form.QiShu;
                m_fts.Clear();
            }
        }

        private void button9_Click(object sender, EventArgs e) {
            // 数据大中小 新增序号
            if (MaxCount != 14 && m_ccString == string.Empty) {
                this.ShowInfo("请选择场次");

                return;
            }

            if (this.ShowYesNoInfo("请确认是否新增序号") != DialogResult.Yes) {
                return;
            }

            var subIndex = DataHelper.AutoIncSubIndex("T3", QiShu, m_ccString, MaxCount);
            SetComboBoxT3IndexData(QiShu, m_ccString);
            comboBoxT3SubIndex.SelectedIndex = comboBoxT3SubIndex.Items.IndexOf(subIndex);
            dzxInput.Focus();
        }

        private void SetComboBoxT3IndexData(string qiShu, string cc) {
            var cb = comboBoxT3SubIndex;
            cb.Items.Clear();
            cb.Items.AddRange(DataHelper.GetT3SubIndexes(qiShu, cc, MaxCount));
            cb.SelectedIndex = cb.Items.IndexOf(qiShu);
            if (cb.SelectedIndex == -1 && cb.Items.Count != 0) {
                cb.SelectedIndex = 0;
            }
        }

        private void comboBoxT3SubIndex_SelectedIndexChanged(object sender, EventArgs e) {
            SetT3ControlEnabled(comboBoxT3SubIndex.SelectedIndex != -1);

            dzxInput.ClearData();
            dzxGrid.ClearData();
            dzxInput.SetCC(m_cc);

            if (string.IsNullOrEmpty(comboBoxT3SubIndex.Text)) {
                return;
            }

            List<DZX> data;
            CellData cellData;
            var subIndex = comboBoxT3SubIndex.Text;

            DataHelper.LoadT3Data(QiShu, m_ccString, MaxCount, subIndex, out data, out cellData);
            for (int i = 0; i < data.Count; i++) {
                var item = data[i];
                var control = dzxInput[i];
                control.Three = item.Three;
                control.One = item.One;
                control.Zero = item.Zero;
                control.PreText = item.PreText;
                control.SetDZXLabelInfo();
            }
            dzxGrid.SetCellData(cellData);
        }

        private void button13_Click(object sender, EventArgs e) {
            // 表三 复制与表1相同的数据

            if (comboBoxT3SubIndex.SelectedIndex == -1) {
                this.ShowInfo("没有选择序号");
                return;
            }

            var order = comboBoxT3SubIndex.Text;
            if (comboBoxT1SubIndex.Items.IndexOf(order) == -1) {
                this.ShowInfo(string.Format("表1中还没有序号 {0} ", order));
                return;
            }
            if (this.ShowYesNoInfo("请确认是否进行数据复制?") != DialogResult.Yes) {
                dzxInput.Focus();
                return;
            }

            dzxGrid.ClearData();
            List<DS> d;
            List<FD> f;
            CL c;
            DataHelper.LoadT1Data(QiShu, m_ccString, MaxCount, order, out d, out f, out c);
            if (d == null || d.Count == 0) {
                this.ShowInfo("表1中没有数据，无法复制");
                return;
            }

            for (int i = 0; i < dzxInput.Count; i++) {
                var item = dzxInput[i];
                var data = d[i];
                var preText = item.PreText;
                item.Clear();

                item.Three = data.Three;
                item.One = data.One;
                item.Zero = data.Zero;
                item.PreText = preText;
                item.SetDZXLabelInfo();
            }
            this.ShowInfo("成功复制数据");
            dzxInput.Focus();
        }

        private void comboBoxT4SubIndex_SelectedIndexChanged(object sender, EventArgs e) {
            wzInput.ClearData();
            wzGrid.ClearData();
            wzInput.SetCC(m_cc);
            wzInput.SetDefaultValue();
            SetT4ControlEnabled(comboBoxT4SubIndex.SelectedIndex != -1);

            if (string.IsNullOrEmpty(comboBoxT4SubIndex.Text)) {
                return;
            }

            List<WZ> data;
            CellData cellData;
            var subIndex = comboBoxT4SubIndex.Text;
            string text;
            DataHelper.LoadT4Data(QiShu, m_ccString, MaxCount, subIndex, out data, out cellData, out text);
            wzOption.OptionText = text;
            for (int i = 0; i < data.Count; i++) {
                var item = data[i];
                var control = wzInput[i];
                control.Three = item.Three;
                control.One = item.One;
                control.Zero = item.Zero;
                control.PreText = item.PreText;
            }
            wzGrid.SetCellData(cellData);
        }

        private void buttonT4AutoInc_Click(object sender, EventArgs e) {
            // 表四 新增序号
            if (MaxCount != 14 && m_ccString == string.Empty) {
                this.ShowInfo("请选择场次");

                return;
            }

            if (this.ShowYesNoInfo("请确认是否新增序号") != DialogResult.Yes) {
                return;
            }

            var subIndex = DataHelper.AutoIncSubIndex("T4", QiShu, m_ccString, MaxCount);
            SetComboBoxT4IndexData(QiShu, m_ccString);
            comboBoxT4SubIndex.SelectedIndex = comboBoxT4SubIndex.Items.IndexOf(subIndex);

            wzInput.Focus();
        }

        private void SetComboBoxT4IndexData(string qiShu, string cc) {
            var cb = comboBoxT4SubIndex;
            cb.Items.Clear();
            cb.Items.AddRange(DataHelper.GetT4SubIndexes(qiShu, cc, MaxCount));
            if (cb.SelectedIndex == -1 && cb.Items.Count != 0) {
                cb.SelectedIndex = 0;
            }
        }

        private void buttonSaveT4Data_Click(object sender, EventArgs e) {
            for (int i = 0; i < wzInput.Count; i++) {
                var item = wzInput[i];
                if (!item.IsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据没有完整录入", i + 1));
                    item.Focus();
                    return;
                }

                if (!item.InputIsOK) {
                    this.ShowInfo(string.Format("第 {0} 场数据录入错误：3、1、0的文字相同。", i + 1));
                    item.Focus();
                    return;
                }
            }

            SaveT4Data(comboBoxT4SubIndex.Text);

            this.ShowInfo("成功保存数据");
            wzInput.Focus();
        }

        private void SaveT4Data(string order) {
            var d = new List<WZ>();
            for (int i = 0; i < wzInput.Count; i++) {
                var item = wzInput[i];
                if (item.Enabled)
                    d.Add(new WZ() {
                        Three = item.Three, One = item.One, Zero = item.Zero,
                        PreText = item.PreText
                    });
                else
                    d.Add(new WZ() { Three = "", One = "", Zero = "", PreText = "" });

            }

            var cellData = wzGrid.GetCellData();
            DataHelper.SaveT4Data(QiShu, m_ccString, MaxCount, order, d, cellData, wzOption.OptionText);
        }

        private void wzOption_Selected(object sender, EventArgs e) {
            for (int i = 0; i < wzInput.Count; i++) {
                var item = wzInput[i];
                item.SetText(wzOption.OptionText);
            }
            wzGrid.SetText(wzOption.OptionText);
        }

        private void buttonGenAllFilterTable_Click(object sender, EventArgs e) {
            // 生成本期所有的过滤表
            if (MaxCount != 14 && cbNine.SelectedIndex == -1) {
                this.ShowInfo("没有选择场次组合");
                return;
            }

            if (this.ShowYesNoInfo("请确认是否生成所有的过滤表") != DialogResult.Yes) {
                return;
            }

            // table 1
            var t1SubIndexes = DataHelper.GetT1SubIndexes(QiShu, m_ccString, MaxCount);
            foreach (var subIndex in t1SubIndexes) {
                List<DS> d;
                List<FD> f;
                CL c;
                DataHelper.LoadT1Data(QiShu, m_ccString, MaxCount, subIndex, out d, out f, out c);
                if (d == null || d.Count == 0 || f == null || f.Count == 0 || c.From1 == -1) {
                    var info = string.Format("表1中序号为{0}的数据没有录入完整，不能生成所有的的过滤表。\n\n是否现在就查看表1的数据?", subIndex);
                    if (this.ShowYesNoInfo(info) == DialogResult.Yes) {
                        tabControl.SelectedIndex = 0;
                        comboBoxT1SubIndex.SelectedIndex = comboBoxT1SubIndex.Items.IndexOf(subIndex);
                        mediaDataInput.Focus();
                    }
                    return;
                }

                var ft = new FTCellData();
                MDHelper.Gen(ft, d, f, subIndex);
                MDHelper.CombineLine(ft, f, c);

                var key = m_ccString == string.Empty ? string.Format("1-{0}", subIndex) : string.Format("1-[{1}]-{0}", subIndex, m_ccString);
                m_fts[key] = ft;
            }

            // table 2
            var t2SubIndexes = DataHelper.GetT2SubIndexes(QiShu, m_ccString, MaxCount);
            foreach (var subIndex in t2SubIndexes) {
                List<SC> d;
                List<FD> f;
                CL c;
                DataHelper.LoadT2Data(QiShu, m_ccString, MaxCount, subIndex, out d, out f, out c);
                if (d == null || d.Count == 0 || f == null || f.Count == 0) {
                    var info = string.Format("表2中序号为{0}的数据没有录入完整，不能生成所有的的过滤表。\n\n是否现在就查看表2的数据?", subIndex);
                    if (this.ShowYesNoInfo(info) == DialogResult.Yes) {
                        tabControl.SelectedIndex = 1;
                        comboBoxT2SubIndex.SelectedIndex = comboBoxT2SubIndex.Items.IndexOf(subIndex);
                        scInput.Focus();
                    }
                    return;
                }

                var ft = new FTCellData();
                SCHelper.Gen(ft, d, f, subIndex);
                SCHelper.CombineLine(ft, f, c);
                var key = m_ccString == string.Empty ? string.Format("2-{0}", subIndex) : string.Format("2-[{1}]-{0}", subIndex, m_ccString);
                m_fts[key] = ft;
            }

            // table 3
            var t3SubIndexes = DataHelper.GetT3SubIndexes(QiShu, m_ccString, MaxCount);
            foreach (var subIndex in t3SubIndexes) {
                List<DZX> d;
                CellData f;
                DataHelper.LoadT3Data(QiShu, m_ccString, MaxCount, subIndex, out d, out f);
                if (d == null || d.Count == 0 || f == null) {
                    var info = string.Format("表3中序号为{0}的数据没有录入完整，不能生成所有的的过滤表。\n\n是否现在就查看表3的数据?", subIndex);
                    if (this.ShowYesNoInfo(info) == DialogResult.Yes) {
                        tabControl.SelectedIndex = 2;
                        comboBoxT3SubIndex.SelectedIndex = comboBoxT3SubIndex.Items.IndexOf(subIndex);
                        dzxInput.Focus();
                    }
                    return;
                }

                var ft = new FTCellData();
                var grid = new DZXGrid();
                grid.InitGrid();
                grid.SetCellData(f);
                grid.GenFtCellData(ft, subIndex);
                var key = m_ccString == string.Empty ? string.Format("3-{0}", subIndex) : string.Format("3-[{1}]-{0}", subIndex, m_ccString);
                m_fts[key] = ft;
            }

            // table 4
            var t4SubIndexes = DataHelper.GetT4SubIndexes(QiShu, m_ccString, MaxCount);
            foreach (var subIndex in t4SubIndexes) {
                List<WZ> d;
                CellData f;
                string text;
                DataHelper.LoadT4Data(QiShu, m_ccString, MaxCount, subIndex, out d, out f, out text);
                if (d == null || d.Count == 0 || f == null) {
                    var info = string.Format("表4中序号为{0}的数据没有录入完整，不能生成所有的的过滤表。\n\n是否现在就查看表4的数据?", subIndex);
                    if (this.ShowYesNoInfo(info) == DialogResult.Yes) {
                        tabControl.SelectedIndex = 3;
                        comboBoxT4SubIndex.SelectedIndex = comboBoxT4SubIndex.Items.IndexOf(subIndex);
                        wzInput.Focus();
                    }
                    return;
                }

                var ft = new FTCellData();
                var grid = new WZGrid();
                grid.InitGrid();
                grid.SetText(text);
                grid.SetCellData(f);
                grid.GenFtCellData(ft, subIndex);
                var key = m_ccString == string.Empty ? string.Format("4-{0}", subIndex) : string.Format("4-[{1}]-{0}", subIndex, m_ccString);
                m_fts[key] = ft;
            }

            ShowFilterForm(QiShu, string.Empty);
        }

        private void buttonNewCC_Click(object sender, EventArgs e) {
            var form = new NewCCForm(QiShu, MaxCount);
            if (form.ShowDialog() == DialogResult.OK) {
                var cc = form.CC;
                var index = cbNine.Items.IndexOf(cc);
                if (index == -1) {
                    SetCC();
                    cbNine.SelectedIndex = cbNine.Items.IndexOf(cc);
                } else
                    cbNine.SelectedIndex = index;
            }
        }

        private void cbNine_SelectedIndexChanged(object sender, EventArgs e) {
            if (cbNine.SelectedIndex == -1) {
                return;
            }

            m_fts.Clear();
            m_ccString = cbNine.Text;

            m_cc = (from item in m_ccString.Split('-') select Convert.ToInt32(item) - 1).ToList();

            mediaDataInput.ClearData();
            dataLimitInput.HideAll();
            mediaDataInput.SetCC(m_cc);

            scInput.ClearData();
            dataLimitInputSC.HideAll();
            scInput.SetCC(m_cc);

            dzxInput.ClearData();
            dzxGrid.ClearData();
            dzxInput.SetCC(m_cc);

            wzInput.ClearData();
            wzGrid.ClearData();
            wzInput.SetCC(m_cc);

            SetComboBoxT1IndexData(QiShu, m_ccString);
            SetComboBoxT2IndexData(QiShu, m_ccString);
            SetComboBoxT3IndexData(QiShu, m_ccString);
            SetComboBoxT4IndexData(QiShu, m_ccString);
        }

        private void buttonLine1_Click(object sender, EventArgs e) {
            // 表一 合并行

            var hasCombinData = false;
            for (int i = 0; i < dataLimitInput.Count; i++) {
                if (dataLimitInput[i].Visible) {
                    hasCombinData = true;
                    break;
                }
            }
            if (!hasCombinData) {
                this.ShowInfo("没有进行数据合并");
                this.Focus();
                return;
            }

            var sl = new List<int>();
            for (int i = 0; i < dataLimitInput.Count; i++) {
                var dl = dataLimitInput[i];
                if (dl.Visible)
                    sl.Add(dl.MediaCount);
            }

            var combines = (from item in sl
                            orderby item ascending
                            select item.ToString()).ToList();

            var form = new CombineLineForm(combines);
            form.From1 = combineLineT1.From1;
            form.To1 = combineLineT1.To1;
            form.From2 = combineLineT1.From2;
            form.To2 = combineLineT1.To2;

            if (form.ShowDialog() == DialogResult.OK) {
                combineLineT1.From1 = form.From1;
                combineLineT1.To1 = form.To1;
                combineLineT1.From2 = form.From2;
                combineLineT1.To2 = form.To2;
            }
        }

        private void buttonLine2_Click(object sender, EventArgs e) {
            // 表二 合并行

            var hasCombinData = false;
            for (int i = 0; i < scInput.Count; i++) {
                if (scInput[i].Visible) {
                    hasCombinData = true;
                    break;
                }
            }
            if (!hasCombinData) {
                this.ShowInfo("没有进行数据合并");
                this.Focus();
                return;
            }

            var sl = new List<int>();
            for (int i = 0; i < dataLimitInputSC.Count; i++) {
                var dl = dataLimitInputSC[i];
                if (dl.Visible)
                    sl.Add(dl.MediaCount);
            }
            var combines = (from item in sl
                            orderby item ascending
                            select item.ToString()).ToList();

            var form = new CombineLineForm(combines);
            form.From1 = combineLineT2.From1;
            form.To1 = combineLineT2.To1;
            form.From2 = combineLineT2.From2;
            form.To2 = combineLineT2.To2;

            if (form.ShowDialog() == DialogResult.OK) {
                combineLineT2.From1 = form.From1;
                combineLineT2.To1 = form.To1;
                combineLineT2.From2 = form.From2;
                combineLineT2.To2 = form.To2;
            }
        }

        private void buttonDeleteT1AutoNum_Click(object sender, EventArgs e) {
            // 删除表1的序号
            var selectedIndex = comboBoxT1SubIndex.SelectedIndex;
            if (selectedIndex == -1) {
                this.ShowInfo("表1没有序号可以删除");
                return;
            }

            var index = comboBoxT1SubIndex.Items[selectedIndex].ToString();
            var info = string.Format("请确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            info = string.Format("数据删除后不能恢复，请再次确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            // 删除序号操作
            DataHelper.DeleteSubIndex("T1", QiShu, m_ccString, index, MaxCount);

            //刷新界面
            SetComboBoxT1IndexData(QiShu, m_ccString);
            comboBoxT1SubIndex.SelectedIndex = comboBoxT1SubIndex.Items.Count > 0 ? 0 : -1;
            if (comboBoxT1SubIndex.SelectedIndex == -1) {
                SetT1ControlEnabled(comboBoxT1SubIndex.SelectedIndex != -1);

                mediaDataInput.ClearData();
                dataLimitInput.HideAll();
                mediaDataInput.SetCC(m_cc);

                combineLineT1.ClearData();
            }
        }

        private void buttonDeleteT2AutoNum_Click(object sender, EventArgs e) {
            // 删除表2序号
            var cb = comboBoxT2SubIndex;
            var selectedIndex = cb.SelectedIndex;
            if (selectedIndex == -1) {
                this.ShowInfo("表2没有序号可以删除");
                return;
            }

            var index = cb.Items[selectedIndex].ToString();
            var info = string.Format("请确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            info = string.Format("数据删除后不能恢复，请再次确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            // 删除序号操作
            DataHelper.DeleteSubIndex("T2", QiShu, m_ccString, index, MaxCount);

            //刷新界面
            SetComboBoxT2IndexData(QiShu, m_ccString);
            cb.SelectedIndex = cb.Items.Count > 0 ? 0 : -1;
            if (cb.SelectedIndex == -1) {
                SetT2ControlEnabled(cb.SelectedIndex != -1);

                scInput.ClearData();
                dataLimitInputSC.HideAll();
                scInput.SetCC(m_cc);

                combineLineT2.ClearData();
            }
        }

        private void buttonDeleteT3AutoNum_Click(object sender, EventArgs e) {
            // 删除表3序号
            var cb = comboBoxT3SubIndex;
            var selectedIndex = cb.SelectedIndex;
            if (selectedIndex == -1) {
                this.ShowInfo("表3没有序号可以删除");
                return;
            }

            var index = cb.Items[selectedIndex].ToString();
            var info = string.Format("请确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            info = string.Format("数据删除后不能恢复，请再次确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            // 删除序号操作
            DataHelper.DeleteSubIndex("T3", QiShu, m_ccString, index, MaxCount);

            //刷新界面
            SetComboBoxT3IndexData(QiShu, m_ccString);
            cb.SelectedIndex = cb.Items.Count > 0 ? 0 : -1;
            if (cb.SelectedIndex == -1) {
                SetT3ControlEnabled(cb.SelectedIndex != -1);

                dzxInput.ClearData();
                dzxGrid.ClearData();
                dzxInput.SetCC(m_cc);
            }
        }

        private void buttonDeleteT4AutoNum_Click(object sender, EventArgs e) {
            // 删除表4序号
            var cb = comboBoxT4SubIndex;
            var selectedIndex = cb.SelectedIndex;
            if (selectedIndex == -1) {
                this.ShowInfo("表4没有序号可以删除");
                return;
            }

            var index = cb.Items[selectedIndex].ToString();
            var info = string.Format("请确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            info = string.Format("数据删除后不能恢复，请再次确认是否删除序号：{0} ?", index);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            // 删除序号操作
            DataHelper.DeleteSubIndex("T4", QiShu, m_ccString, index, MaxCount);

            //刷新界面
            SetComboBoxT4IndexData(QiShu, m_ccString);
            cb.SelectedIndex = cb.Items.Count > 0 ? 0 : -1;
            if (cb.SelectedIndex == -1) {
                wzInput.ClearData();
                wzGrid.ClearData();
                wzInput.SetCC(m_cc);

                SetT4ControlEnabled(cb.SelectedIndex != -1);
            }
        }

        private void buttonLoadData_Click(object sender, EventArgs e) {
            //表1复制14场同序号数据
            if (MaxCount != 14 && string.IsNullOrEmpty(m_ccString)) {
                this.ShowInfo("没有选择场次组合");
                return;
            }

            var defaultSubIndex = comboBoxT1SubIndex.Text;
            var form = new SelectSubIndexFrom14(QiShu, "T1", m_ccString, defaultSubIndex, MaxCount);
            if (form.ShowDialog() == DialogResult.OK) {
                var subIndex = comboBoxT1SubIndex.Text;
                SetComboBoxT1IndexData(QiShu, m_ccString);
                comboBoxT1SubIndex.SelectedIndex = comboBoxT1SubIndex.Items.IndexOf(subIndex);
                if (comboBoxT1SubIndex.SelectedIndex == -1 && comboBoxT1SubIndex.Items.Count > 0) {
                    comboBoxT1SubIndex.SelectedIndex = 0;
                }
            }
        }

        private void buttonLoadDataT2_Click(object sender, EventArgs e) {
            //表2复制14场数据
            if (MaxCount != 14 && string.IsNullOrEmpty(m_ccString)) {
                this.ShowInfo("没有选择场次组合");
                return;
            }
            var defaultSubIndex = comboBoxT2SubIndex.Text;
            var form = new SelectSubIndexFrom14(QiShu, "T2", m_ccString, defaultSubIndex, MaxCount);
            if (form.ShowDialog() == DialogResult.OK) {
                var subIndex = comboBoxT2SubIndex.Text;
                SetComboBoxT2IndexData(QiShu, m_ccString);
                comboBoxT2SubIndex.SelectedIndex = comboBoxT2SubIndex.Items.IndexOf(subIndex);
                if (comboBoxT2SubIndex.SelectedIndex == -1 && comboBoxT2SubIndex.Items.Count > 0) {
                    comboBoxT2SubIndex.SelectedIndex = 0;
                }
            }
        }

        private void buttonLoadDataT3_Click(object sender, EventArgs e) {
            //表3复制14场数据
            if (MaxCount != 14 && string.IsNullOrEmpty(m_ccString)) {
                this.ShowInfo("没有选择场次组合");
                return;
            }
            var defaultSubIndex = comboBoxT3SubIndex.Text;
            var form = new SelectSubIndexFrom14(QiShu, "T3", m_ccString, defaultSubIndex, MaxCount);
            if (form.ShowDialog() == DialogResult.OK) {
                var subIndex = comboBoxT3SubIndex.Text;
                SetComboBoxT3IndexData(QiShu, m_ccString);
                comboBoxT3SubIndex.SelectedIndex = comboBoxT3SubIndex.Items.IndexOf(subIndex);
                if (comboBoxT3SubIndex.SelectedIndex == -1 && comboBoxT3SubIndex.Items.Count > 0) {
                    comboBoxT3SubIndex.SelectedIndex = 0;
                }
            }
        }

        private void buttonLoadDataT4_Click(object sender, EventArgs e) {
            //表4 复制14场数据
            if (MaxCount != 14 && string.IsNullOrEmpty(m_ccString)) {
                this.ShowInfo("没有选择场次组合");
                return;
            }
            var defaultSubIndex = comboBoxT4SubIndex.Text;
            var form = new SelectSubIndexFrom14(QiShu, "T4", m_ccString, defaultSubIndex, MaxCount);
            if (form.ShowDialog() == DialogResult.OK) {
                var subIndex = comboBoxT4SubIndex.Text;
                SetComboBoxT4IndexData(QiShu, m_ccString);
                comboBoxT4SubIndex.SelectedIndex = comboBoxT4SubIndex.Items.IndexOf(subIndex);
                if (comboBoxT4SubIndex.SelectedIndex == -1 && comboBoxT4SubIndex.Items.Count > 0) {
                    comboBoxT4SubIndex.SelectedIndex = 0;
                }
            }
        }

        private void buttonLoadDataFromExc_Click(object sender, EventArgs e) {
            // 从Excel中批量导入数据
            if (openFileDialog.ShowDialog() != DialogResult.OK) {
                return;
            }
            var info = string.Format("请确认是否导入 {0} 中的数据?", openFileDialog.FileName);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            var result = Lottery.MediaData.Core.ETHelper.Import2(openFileDialog.FileName, QiShu);
            this.ShowInfo(result);

            SetComboBoxT1IndexData(QiShu, m_ccString);
            if (comboBoxT1SubIndex.Items.Count > 0) comboBoxT1SubIndex.SelectedIndex = 0;

            SetComboBoxT2IndexData(QiShu, m_ccString);
            if (comboBoxT2SubIndex.Items.Count > 0) comboBoxT2SubIndex.SelectedIndex = 0;

            SetComboBoxT3IndexData(QiShu, m_ccString);
            if (comboBoxT3SubIndex.Items.Count > 0) comboBoxT3SubIndex.SelectedIndex = 0;

            SetComboBoxT4IndexData(QiShu, m_ccString);
            if (comboBoxT4SubIndex.Items.Count > 0) comboBoxT4SubIndex.SelectedIndex = 0;
        }

        private void buttonDeleteCC_Click(object sender, EventArgs e) {
            // 删除场次组合
            if (cbNine.SelectedIndex == -1) {
                this.ShowInfo("请选择要删除的场次组合");
                return;
            }

            var cc = cbNine.Items[cbNine.SelectedIndex].ToString();
            var info = string.Format("请确认是否删除场次组合：{0} ?", cc);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            info = string.Format("因为删除后数据不能恢复，请再次确认是否删除场次组合：{0} ?", cc);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            DataHelper.DeleteCC(QiShu, m_ccString, MaxCount);
            SetCC();
            if (cbNine.Items.Count > 0) cbNine.SelectedIndex = 0;

        }

        private void buttonLoadCCFromExcel_Click(object sender, EventArgs e) {
            // 批量调入场次组合（从Excel中）
            if (openFileDialog.ShowDialog() != DialogResult.OK) {
                return;
            }
            var info = string.Format("请确认是否导入 {0} 中的数据?", openFileDialog.FileName);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            var result = Lottery.MediaData.Core.ETHelper.Import3(openFileDialog.FileName, QiShu, MaxCount);
            this.ShowInfo(result);
            SetCC();
            if (cbNine.Items.Count > 0) cbNine.SelectedIndex = 0;
        }

        private void button2_Click_2(object sender, EventArgs e) {
            // 表3：从Excel中批量调入数据：调入预测文字
            if (MaxCount != 14 && m_ccString == string.Empty) {
                this.ShowInfo("请选择场次");

                return;
            }

            if (openFileDialog.ShowDialog() != DialogResult.OK) {
                return;
            }
            var info = string.Format("请确认是否导入 {0} 中的数据?", openFileDialog.FileName);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            var result = Lottery.MediaData.Core.ETHelper.Import4(openFileDialog.FileName, QiShu, MaxCount, m_cc, m_ccString);
            SetComboBoxT3IndexData(QiShu, m_ccString);
            if (comboBoxT3SubIndex.Items.Count > 0) {
                comboBoxT3SubIndex.SelectedIndex = 0;
            }
            
            this.ShowInfo(result);
        }

        private void button3_Click_1(object sender, EventArgs e) {
            // 表4：从Excel中批量调入数据：预测文字
            if (MaxCount != 14 && m_ccString == string.Empty) {
                this.ShowInfo("请选择场次");

                return;
            }

            if (openFileDialog.ShowDialog() != DialogResult.OK) {
                return;
            }
            var info = string.Format("请确认是否导入 {0} 中的数据?", openFileDialog.FileName);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            var result = Lottery.MediaData.Core.ETHelper.Import5(openFileDialog.FileName, QiShu, MaxCount, m_cc, m_ccString);
            SetComboBoxT4IndexData(QiShu, m_ccString);
            if (comboBoxT4SubIndex.Items.Count > 0) {
                comboBoxT4SubIndex.SelectedIndex = 0;
            }

            this.ShowInfo(result);
        }
    }
}
